<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">注册花城</view>
			<input class="u-border-bottom" v-model="tel" placeholder="请输入用户名" />
			<input class="u-border-bottom" type="number" v-model="possword" placeholder="请输入密码" />
			<button @tap="submit" :style="[inputStyle]" class="getCaptcha">注册</button>
			<view class="alternative">
				<view class="issue">遇到问题</view>
			</view>
		</view>
		<view>
			<u-toast ref="uToast" />
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tel: '',
				possword: ''
			}
		},
		computed: {
			inputStyle() {
				let style = {};
				if (this.tel && this.possword) {
					style.color = "#fff";
					style.backgroundColor = this.$u.color['warning'];
				}
				return style;
			}
		},
		methods: {
			async submit() {
				if (this.tel && this
					.possword) {
					let {
						data: res
					} = await this.$http("/register", "post", {},{
						username: this.tel,
						password: this.possword,
					})
					console.log(res)
					if (res.code == 200 && res.data.msg.length == 6) {
						uni.navigateTo({
							url: '/pages/login/index'
						})
					}
					this.$refs.uToast.show({
						title: res.data.msg,
						type: 'error',
					})
				}
			},
		}
	};
</script>

<style lang="scss" scoped>
	.wrap {
		font-size: 28rpx;

		.content {
			width: 600rpx;
			margin: 80rpx auto 0;

			.title {
				text-align: left;
				font-size: 60rpx;
				font-weight: 500;
				margin-bottom: 100rpx;
			}

			input {
				text-align: left;
				margin-bottom: 10rpx;
				padding-bottom: 6rpx;
			}

			.tips {
				color: $u-type-info;
				margin-bottom: 60rpx;
				margin-top: 8rpx;
			}

			.getCaptcha {
				background-color: rgb(253, 243, 208);
				color: $u-tips-color;
				border: none;
				font-size: 30rpx;
				padding: 12rpx 0;

				&::after {
					border: none;
				}
			}

			.alternative {
				color: $u-tips-color;
				display: flex;
				justify-content: space-between;
				margin-top: 30rpx;
			}
		}
	}
</style>
